<template>
  <div class="add-card pointer" v-if="inputFlag" @click="inputFlag = false">
    <el-icon class="pr5">
      <Plus/>
    </el-icon>
    <span class="ml-2">添加卡片</span>
  </div>
  <div class="add-card-input" v-else>
    <el-input class="input" v-model="cardNameValue" placeholder="输入卡片名称..."></el-input>
    <div class="btn-container">
      <el-button type="primary" @click="handleAddCard">添加卡片</el-button>
      <div class="common-icon pointer ml-2" @click="inputFlag = true">
        <el-icon >
          <Close/>
        </el-icon>
      </div>
    </div>
  </div>
</template>

<script setup>
import {ref} from "vue";
import {Close, Plus} from "@element-plus/icons-vue";
import {addCard} from "@/api/card.js";
const props = defineProps({
  id: String
})
const emit = defineEmits(['addCard'])
const inputFlag = ref(true);
const cardNameValue = ref(null);
const handleAddCard = async () => {
  const param = {
    id: props.id,
    cardName: cardNameValue.value
  }
  const res = await addCard(param);
  if (res.code === 200) {
    inputFlag.value = true;
    cardNameValue.value = ''
    emit('addCard')
  }
}
</script>


<style scoped lang="less">
.add-card {
  width: 100%;
  height: 30px;
  padding: 5px 5px 5px 10px;
  display: flex;
  align-items: center;
  word-wrap: break-word;
  border-radius: 6px;
  background: transparent;

  transition: all 0.3s ease-in-out;
  &:hover {
    background: #e0e0e0;
  }
}
.add-card-input {
  width: 100%;
  height: 100px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  border-radius: 10px;

  .input {
    width: 240px;
  }
  .btn-container {
    width: 240px;
    margin-top: 10px;
    display: flex;
    justify-content: flex-start;
  }
}
</style>
